package com.cn.byjk.config;

import com.cn.byjk.Constant.RabbitConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhangdianzhi
 * @version v1.0
 * @description rabbitmq交换机配置
 * @date 2022/1/6 11:59
 */
@Configuration
public class RabbitExchangeConfig {
        //直连交换机
        @Bean
        public DirectExchange defaultExchange() {
            return new DirectExchange(RabbitConstant.EXCHANGE_NAME);
        }

        //队列
        @Bean
        public Queue queue() {
            return QueueBuilder.durable(RabbitConstant.QUEUE_NAME).build();
        }

        //绑定
        @Bean
        public Binding binding() {
            return BindingBuilder.bind(this.queue()).to(this.defaultExchange()).with(RabbitConstant.ROUTING_KEY);
        }

}
